package org.hot100_1;

public class leetcode16 {
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        //left[i]表示num[i]左侧的所有乘积，不包括num[i]
        int [] left =new int[n];
        //right[i]表示num[i]右侧的所有乘积，不包括num[i]
        int [] right = new int[n];

        int [] res =new int [n];

        left[0]=right[n-1]=1;

        for (int i = 1; i <n; i++) {
            left[i]=left[i-1]*nums[i-1];
        }

        for (int i = n-2; i >=0; i--) {
            right[i]=right[i+1]*nums[i+1];
        }

        for (int i = 0; i < n; i++) {
            res[i]=left[i]*right[i];
        }

        return res;
    }
}
